package com.gx.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.gx.exception.DataBaseConnectFailedException;
import com.gx.str.ExMsgStr;

public class DBHelperOracl {
	private static volatile Connection connection = null;

	private DBHelperOracl() {
	}

	// 数据库连接单例
	public static Connection getConnection() throws  DataBaseConnectFailedException{
		String url = "jdbc:oracle:thin:@172.16.150.16:1521:orcl";
		String driver = "oracle.jdbc.driver.OracleDriver";
		String user = "ring";
		String password = "ring2017";
		try {
			Class.forName(driver);
			if (connection == null || connection.isClosed()) {
				synchronized (DBHelperOracl.class) {
					connection = DriverManager.getConnection(url, user, password);
				}

			}
		} catch (ClassNotFoundException e) {
			throw new DataBaseConnectFailedException(ExMsgStr.MSG_EX03,e );
			
		} catch (SQLException e) {
			throw new DataBaseConnectFailedException(ExMsgStr.MSG_EX03+url,e);
		}

		return connection;
	}
}
